package com.wanmait.employment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.employment.entity.EducationalExperience;
import com.wanmait.employment.entity.JobExperience;
import com.wanmait.employment.entity.Userinfo;
import com.wanmait.employment.mapper.JobExperienceMapper;
import com.wanmait.employment.mapper.UserinfoMapper;
import com.wanmait.employment.service.JobExperienceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class JobExperienceServiceImpl implements JobExperienceService {
    @Resource
    private JobExperienceMapper jobExperienceMapper;
    @Resource
    private UserinfoMapper userinfoMapper;
    @Override
    public PageInfo<JobExperience> selectList(String title, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper<JobExperience> queryWrapper=new QueryWrapper<>();
        queryWrapper.like("company_name",title).or().like("duty",title).or().like("industry_name",title).
        or().inSql("userinfo_id", "SELECT id FROM userinfo WHERE name like '%"+title+"%'");
        List<JobExperience> jobExperienceList=jobExperienceMapper.selectList(queryWrapper);
        PageInfo<JobExperience> jobExperiencePageInfo=new PageInfo<>(jobExperienceList);
        jobExperiencePageInfo.getList().forEach((jobExperience) -> {
            QueryWrapper<Userinfo> userinfoQueryWrapper=new QueryWrapper<>();
            userinfoQueryWrapper.eq("id",jobExperience.getUserinfoId());
            Userinfo userinfo=userinfoMapper.selectOne(userinfoQueryWrapper);
            jobExperience.setUserinfo(userinfo);
        });
        return jobExperiencePageInfo;
    }

    @Override
    public Boolean insert(JobExperience jobExperience) {
        return null;
    }

    @Override
    public void update(JobExperience jobExperience) {

    }

    @Override
    public void delete(Integer id) {
        jobExperienceMapper.deleteById(id);
    }

    @Override
    public List<JobExperience> selectId(Integer userinfoId) {
        QueryWrapper<JobExperience> jobExperienceQueryWrapper=new QueryWrapper<>();
        jobExperienceQueryWrapper.eq("userinfo_id",userinfoId);
        List<JobExperience> jobExperienceList=jobExperienceMapper.selectList(jobExperienceQueryWrapper);
        return jobExperienceList;
    }


}
